package com.googlecode.yami;

import java.sql.Connection;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;

import java.awt.*;

public class MainWindow extends JFrame {

    static final String DEFAULT_HOST = "localhost";
    static final String VERSION = "0.2";
    static final JTabbedPane JTP = new JTabbedPane();
    static final TextTransfer clipboard = new TextTransfer();

    // static status bar
    // connect.login() function sets this parameter after login
    public static String whoIs;
    private Box bottomBar;
    static JLabel STATUS_BAR = new JLabel("Version " + VERSION);
    private final JLabel WHO_CONNECTS = new JLabel(whoIs);

    MainWindow(final Connection srvConn) {

	super("YAMI " + VERSION);
	setSize(800, 600);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JTP.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
	setJMenuBar(new MainMenu(srvConn));

	bottomBar = new Box(BoxLayout.X_AXIS);
	bottomBar.add(Box.createHorizontalGlue());

	// initializing the bars
	bottomBar.add(WHO_CONNECTS);
	bottomBar.add(Box.createHorizontalStrut(10));
	bottomBar.add(STATUS_BAR);
	bottomBar.add(Box.createHorizontalStrut(10));

	// ****************

	Container cp = getContentPane();
	cp.add(JTP);
	cp.add(bottomBar, BorderLayout.SOUTH);
    }

    // create the main window
    public static void main(String[] args) {
	Connection srvConn;
	srvConn = ConnectionDialog.getConnection();
	if (srvConn != null) {
	    MainWindow mw = new MainWindow(srvConn);
	    mw.setVisible(true);
	    /* testing only
	    new BoxComponent(srvConn);
	    */
	}
    }

}
